package chapter20;

import java.io.Serializable;
import java.util.Comparator;

/**
 * @program: exercise
 * @description: 示例说明comparator, 用于比较没有实现comparable接口的类对象
 * ps:java API 中的一些类比如String Date Calendar BigInterger BigDecimal等基本数据类型都实现了comparable接口。
 * @author: 陈庆彪
 * @create: 2020-02-22 10:06
 **/
public class GeometricObjectCompartor implements Comparator<GeometricObject>, Serializable {

    @Override
    public int compare(GeometricObject o1, GeometricObject o2) {
       double area1=o1.getArea();
       double area2=o2.getArea();
       if (area1<area2)
           return -1;
       else if (area1==area2)
           return  0;
       else
           return 1;
    }
}
